package com.leyou.web;

import com.leyou.item.dto.CategoryDTO;
import com.leyou.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/category")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    /**
     * 根据分类id查询商品分类
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public ResponseEntity<CategoryDTO> getCategoryByCategoryId(@PathVariable("id") long id) {

        return ResponseEntity.ok(categoryService.getCategoryByCategoryId(id));
    }

    /**
     * 根据分类id的集合，查询分类的集合
     * @param ids
     * @return
     */
    @GetMapping("/list")
    public ResponseEntity<List<CategoryDTO>> getCategoriesByList(@RequestParam("ids") List ids) {

        return ResponseEntity.ok(categoryService.getCategoriesByList(ids));

    }

    /**
     * 根据品牌的id，查询商品分类的集合
     * @param id
     * @return
     */
    @GetMapping("/of/brand")
    public ResponseEntity<List<CategoryDTO>> getCategoriesByBrandId(@RequestParam("id") Long id) {
        return  ResponseEntity.ok(categoryService.getCategoriesByBrandId(id));
    }

    /**
     * 根据分类id的集合，查询商品分类的集合
     * @param pid
     * @return
     */
    @GetMapping("/of/parent")
    public ResponseEntity<List<CategoryDTO>> getCategoriesByPid(@RequestParam("pid") Long pid) {
        return  ResponseEntity.ok(categoryService.getCategoriesByPid(pid));
    }
}
